// import { DynamicModule, Global, Logger, Module } from "@nestjs/common";
// import { SequelizeModule } from "@nestjs/sequelize";
// import { DEFAULT_CONNECTION_NAME } from "@nestjs/sequelize/dist/sequelize.constants";
// import { EntitiesMetadataStorage } from "@nestjs/sequelize/dist/entities-metadata.storage";
// import glob from "glob";
// import { chain } from "lodash";
// import { Model } from "sequelize-typescript";

// export interface AutoSequelizeModelModuleOptions {
//   global?: boolean;
//   connection?: string;
//   path: string[];
// }

// @Global()
// @Module({})
// export class AutoSequelizeModelModule {
//   static provide = Symbol("AutoSequelizeModel");

//   static models(connection: string = DEFAULT_CONNECTION_NAME): Function[] {
//     return EntitiesMetadataStorage.getEntitiesByConnection(connection);
//   }

//   static forRoot(data: AutoSequelizeModelModuleOptions): DynamicModule {
//     const connection = data?.connection || DEFAULT_CONNECTION_NAME;

//     const models: any[] = chain(data.path)
//       .map((i) => glob.sync(i))
//       .flatten()
//       .map((path) => require(path))
//       .map((i: any): any[] => {
//         return Object.values(i) as any[];
//       })
//       .flatten()
//       .filter((i) => typeof i === "function" && Model.isPrototypeOf(i))
//       .value();

//     const feature = SequelizeModule.forFeature(models, connection);
//     if (models.length > 0) {
//       Logger.log(
//         `Auto loaded: ${models.map((i) => i.name).join(", ")}`,
//         this.name
//       );
//     } else {
//       Logger.warn(`No models found`, this.name);
//     }

//     const provider = {
//       provide: AutoSequelizeModelModule.provide,
//       useValue: models,
//     };

//     return {
//       module: AutoSequelizeModelModule,
//       global: data.global,
//       imports: [feature],
//       providers: [provider],
//       exports: [provider, feature],
//     };
//   }
// }
